<?php

class IndexController extends CommonController{

    public function __construct()
    {
        parent::__construct();
    }

    public function index(){

        if($_POST){

            $this->checkLogin();
            $post = I($_POST);
            $this->validate($post);
            $post['uid'] = $_SESSION['uid'];
            $res = D('Comments')->addComments($post);

            if($res){

                $this->success('评论成功','index/index');

            }else{

                $this->error('评论失败','index/index');

            }

        }

        $comments = D('Comments') ->getAllComments();

       $this->display('',['comments'=>$comments]);
    }

    public function validate($data){

        if(!$data['contents'] || !isset($data['contents'])){
            $this->error('啥都没写','index/index');
        }
    }
    public function test(){


    }

    public function yzm(){
        $this->yanzhengma();
    }



}

